import json

def checkTbwSuc(l):
    check = True
    for i in l:
        if i > 4:
            check = False
            break
    return check

def getTbwWin6(dmax,dmin):
    win = {}
    for key1 in dmax:
        for key2 in dmin:
            a = [0,0,0,0,0,0,0,0,0]
            for m in range(9):
                a[m] = key1[m] + key2[m]
            if checkTbwSuc(a):
                win[tuple(a)] = {"design":[],"num":0}
                win[tuple(a)]["design"].extend(dmax.get(key1).get("design"))
                win[tuple(a)]["design"].extend(dmin.get(key2).get("design"))
                win[tuple(a)]["num"] = dmax.get(key1).get("num") + dmin.get(key2).get("num")
    return win


def main():
    common = {
        (3,0,0,0,0,0,0,0,0) : {"design":[(1,1,1)],"num":0},
        (0,3,0,0,0,0,0,0,0) : {"design":[(2,2,2)],"num":0},
        (0,0,3,0,0,0,0,0,0) : {"design":[(3,3,3)],"num":0},
        (0,0,0,3,0,0,0,0,0) : {"design":[(4,4,4)],"num":0},
        (0,0,0,0,3,0,0,0,0) : {"design":[(5,5,5)],"num":0},
        (0,0,0,0,0,3,0,0,0) : {"design":[(6,6,6)],"num":0},
        (0,0,0,0,0,0,3,0,0) : {"design":[(7,7,7)],"num":0},
        (0,0,0,0,0,0,0,3,0) : {"design":[(8,8,8)],"num":0},
        (0,0,0,0,0,0,0,0,3) : {"design":[(9,9,9)],"num":0},
        (1,1,1,0,0,0,0,0,0) : {"design":[(1,2,3)],"num":0},
        (0,1,1,1,0,0,0,0,0) : {"design":[(2,3,4)],"num":0},
        (0,0,1,1,1,0,0,0,0) : {"design":[(3,4,5)],"num":0},
        (0,0,0,1,1,1,0,0,0) : {"design":[(4,5,6)],"num":0},
        (0,0,0,0,1,1,1,0,0) : {"design":[(5,6,7)],"num":0},
        (0,0,0,0,0,1,1,1,0) : {"design":[(6,7,8)],"num":0},
        (0,0,0,0,0,0,1,1,1) : {"design":[(7,8,9)],"num":0}
    }

    com139 = {
        (1,0,1,0,0,0,0,0,1) : {"design":[(1,3,9)],"num":1},
        (0,0,0,0,1,0,1,0,1) : {"design":[(5,7,9)],"num":1}
    }

    com13579 = {
        (1,0,1,0,0,0,0,0,1) : {"design":[(1,3,9)],"num":1},
        (0,0,0,0,1,0,1,0,1) : {"design":[(5,7,9)],"num":1}
    }

    #139
    for key in com139:
        common[key] = com139.get(key)

    test = getTbwWin6(common,common)
    file_name = 'test.json'
    file_obj = open(file_name, 'w')
    json_str = json.dump(str(test),file_obj)

    print json_str

if __name__ == '__main__':
    main()